﻿using System.Net;
using System.Text;

using GCC.Container.Abstracts;

namespace GCC.Container.Comm.UDP.Default
{
    public class Client : AbsCommUDPClient<string>
    {
        public Client(IPEndPoint? localInfo, AbsGCCLogger logger, string name, IPEndPoint? target = null) : base(localInfo, logger, name, target)
        {
        }

        protected override bool CheckHeader(in Memory<byte> headBuffer)
        {
            return true;
        }

        protected override int GetBodyLengh(string data)
        {
            return Encoding.UTF8.GetByteCount(data);
        }

        protected override string HandleData(in Memory<byte> _, in Memory<byte> bodyBuffer)
        {
            return Encoding.UTF8.GetString(bodyBuffer.Span);
        }

        protected override void PutData(in Memory<byte> headBuffer, Memory<byte> bodyBuffer, in string data)
        {
            Encoding.UTF8.GetBytes(data).CopyTo(bodyBuffer.Span);
        }

        protected override void PutHeader(Memory<byte> headBuffer, in string data)
        {
        }
    }
}
